package se.webbzon.boltzmann.game.object.dialogue;

import javax.media.j3d.Transform3D;
import javax.vecmath.Vector3d;

import se.webbzon.oschi01.worldobject.appearance.Appearance3D;

public abstract class AbstractDialogueItem {
	
	// The appearance of this dialogue item
	private final Appearance3D appearance;
	
	// The position and size of this dialogue item
	private final Vector3d position, size;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public AbstractDialogueItem(Appearance3D appearance) {
		this.appearance = appearance;
		position = new Vector3d();
		size = new Vector3d();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the 3-dimensional appearance of this dialogue item. **/
	public Appearance3D getAppearance() {
		return appearance;
	}
	
	/** Displays the dialogue item. **/
	public void display() {
		appearance.setVisible(true);
	}
	
	/** Hides the dialogue item. **/
	public void hide() {
		appearance.setVisible(false);
	}
	
	/** Returns true if the dialogue item is hidden. **/
	public boolean isHidden() {
		return !appearance.getVisible();
	}
	
	/** Sets the position of this dialogue item. **/
	public void setPosition(double x, double y, double z) {
		position.set(x,y,z);
		Transform3D transform = new Transform3D();
		appearance.getTransform(transform);
		transform.setTranslation(position);
		appearance.setTransform(transform);
	}
	
	/** Copies the position of this dialogue item to the 
	 * given vector. **/
	public void getPosition(Vector3d position) {
		position.set(this.position);
	}
	
	/** Returns the x-position of this dialogue item. **/
	public double getX() {
		return position.getX();
	}
	
	/** Returns the y-position of this dialogue item. **/
	public double getY() {
		return position.getY();
	}
	
	/** Returns the z-position of this dialogue item. **/
	public double getZ() {
		return position.getZ();
	}
	
	/** Sets the size of this dialogue item. **/
	public void setSize(double width, double height, double depth) {
		size.set(width,height,depth);
		Transform3D transform = new Transform3D();
		transform.setTranslation(position);
		transform.setScale(size);
		appearance.setTransform(transform);
	}
	
	/** Copies the size of this dialogue item to the 
	 * given vector. **/
	public void getSize(Vector3d size) {
		size.set(this.size);
	}
	
	/** Returns the width of this dialogue item. **/
	public double getWidth() {
		return size.getX();
	}
	
	/** Returns the height of this dialogue item. **/
	public double getHeight() {
		return size.getY();
	}
	
	/** Returns the depth of this dialogue item. **/
	public double getDepth() {
		return size.getZ();
	}

}
